package servlet.channel;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.taglibs.standard.tag.el.fmt.RequestEncodingTag;

import jdbc.DBUtils;
import model.News;
import model.NewsChannel;

@WebServlet("/NewsChannelGet")
public class NewsChannelGet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Connection connection = DBUtils.getConn();
		try {
			 String id  = request.getParameter("id");
			 id = new String(id.getBytes("iso-8859-1"),"utf-8");
			PreparedStatement ps = connection.prepareStatement("select * from news_channel where id=?");
			ps.setInt(1,Integer.valueOf(id));
			ResultSet rs = ps.executeQuery();
		
			//这里是一条数据 不用List
			NewsChannel newsChannel = new NewsChannel();
			while (rs.next()) {
				
				newsChannel.setId(rs.getInt("id"));
				newsChannel.setName(rs.getString("name"));
			}
		request.setAttribute("newsChannel", newsChannel);	
		} catch (SQLException e) {
			e.printStackTrace();
		}
		request.getRequestDispatcher("channelset.jsp").forward(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}


